package com.jackrain.nea;

import com.jackrain.nea.core.db.DynamicDataSourceRegister;
import com.jackrain.nea.fc.cp.adutils.ApplicationConstants;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Import;

import java.io.File;

/**
 * Created by jackrain on 16/8/6.
 * Notice:@Import 服务端引入DubboConfig.class，消费端引入DubboConfConsumer.class
 */

@SpringBootApplication
@Import({ModelConfig.class,DynamicDataSourceRegister.class})
public class Main extends SpringBootServletInitializer {

    static {
        System.setProperty("dubbo.application.logger","slf4j");


        StringBuffer keystorebuf = new StringBuffer("");
        keystorebuf.append(System.getProperty("java.home"));
        keystorebuf.append(ApplicationConstants.getProperty("ad.ssl.trustStore"));
        String path = keystorebuf.toString();
        if(new File(path).exists()){
            String storepassword = ApplicationConstants.getProperty("ad.ssl.trustStorePassword");
            System.setProperty("javax.net.ssl.trustStore", keystorebuf.toString());
            System.setProperty("javax.net.ssl.trustStorePassword", storepassword);
        }
    }

    public static void main(String[] args) {
        System.setProperty("spring.devtools.restart.enabled","false");
        ApplicationContext context = SpringApplication.run(applicationClass, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(applicationClass);
    }

    private static Class<Main> applicationClass = Main.class;
}
